<template>
  <div id="app">
    <Topbar :key="topbarkey" />
    <Header />
    <router-view @updataKey="getVal" />
    <Footer />
    <Login v-if="isShowLoginModal"></Login>
    <transition name="fade">
      <Toast v-show="isShowToast" />
    </transition>
  </div>
</template>
<script>
import Topbar from "@/components/Toptabbar.vue";
import Header from "@/components/Header.vue";
import Footer from "@/components/Footer.vue";
import Login from "@/components/Login.vue";
import Toast from "@/components/Toast.vue";

import { mapState } from "vuex";
export default {
  data() {
    return {
      topbarkey: 0,
    };
  },
  components: {
    Topbar,
    Header,
    Footer,
    Login,
    Toast,
  },
  computed: {
    ...mapState({
      isShowLoginModal: (state) => state.showModal.isShowLoginModal,
      isShowToast: (state) => state.showToast.isShowToast,
    }),
  },
  watch: {
    "$route.path": {
      handler() {
        this.topbarkey++; //修改组件key值  让组件重新加载
      },
    },
  },
  methods: {
    getVal() {
      this.topbarkey++;
    },
  },
};
</script>

<style lang="less">
.fade-enter,
.fade-leave-to {
  opacity: 0;
}
.fade-enter-active,
.fade-leave-active {
  transition: opacity 1s linear;
}
.fade-enter-to,
.fade-leave {
  opacity: 1;
}
</style>
